package ejb;

import ejb.FBuser;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;

/**
 *
 * @author Antonio
 */
@Stateless
@LocalBean
public class FBuserManager {
    @EJB
    private FBuserFacade fbuserFacade;

    public void addFBuser(String fbid, String fbname, String oauthtoken, String location) {
        FBuser user = new FBuser();
        user.setFBid(fbid);
        user.setFBname(fbname);
        user.setOAuthToken(oauthtoken);
        user.setLocation(location);
        fbuserFacade.create(user);
    }

    public boolean isNewUser(String fbid) {
        List<FBuser> users = fbuserFacade.findAll();
        for(FBuser found:users){
            if (found.getFBid().equals(fbid))
                return false;
        }
        return true;
    }
    
    public FBuser findFBuser (String fbid){
        List<FBuser> users = fbuserFacade.findAll();
        for(FBuser found:users){
            if (found.getFBid().equals(fbid))
                return found;
        }
        return null;
    }
    
    public List<FBuser> findAllFBuser(){
        return fbuserFacade.findAll();
    }
}
